From 11fd751dd014044f6b0276c192d6e51f1541eb4c Mon Sep 17 00:00:00 2001 From: robertl Date: Sat, 16 Aug 2008 17:43:05 +0000 Subject: [PATCH] Add concept of track line colors. Currently supported only for an1->kml. More to come later. --- gpsbabel/an1.c | 21 +++++++++++++++------ gpsbabel/defs.h | 8 ++++++++ gpsbabel/kml.c | 11 +++++++++++ 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/gpsbabel/an1.c b/gpsbabel/an1.c index c499b12b4..f7b85a570 100644 --- a/gpsbabel/an1.c +++ b/gpsbabel/an1.c @@ -1,6 +1,6 @@ /* Read DeLorme drawing files (.an1) - + Copyright (C) 2005 Ron Parker and Robert Lipe. This program is free software; you can redistribute it and/or modify @@ -224,7 +224,7 @@ typedef struct { long lineweight; long linestyle; long linecolor; - long unk5; + long opacity; long polyfillcolor; long unk6; long unk7; @@ -532,7 +532,7 @@ static void Read_AN1_Line( gbfile *f, an1_line_record *line ) { line->lineweight = ReadShort( f ); line->linestyle = ReadLong( f ); line->linecolor = ReadLong( f ); - line->unk5 = ReadLong( f ); + line->opacity = ReadLong( f ); line->polyfillcolor = ReadLong( f ); line->unk6 = ReadLong( f ); line->unk7 = ReadLong( f ); @@ -555,7 +555,7 @@ static void Write_AN1_Line( gbfile *f, an1_line_record *line ) { WriteShort( f, (short) line->lineweight ); WriteLong( f, line->linestyle ); WriteLong( f, line->linecolor ); - WriteLong( f, line->unk5 ); + WriteLong( f, line->opacity ); WriteLong( f, line->polyfillcolor ); WriteLong( f, line->unk6 ); WriteLong( f, line->unk7 ); @@ -797,6 +797,15 @@ static void Read_AN1_Lines( gbfile *f ) { Read_AN1_Line( f, rec ); /* create route rec */ rte_head = route_head_alloc(); + rte_head->line_color.bbggrr = rec->linecolor; + if (rec->opacity == 0x8200) + rte_head->line_color.opacity = 128; + // lineweight isn't set for dashed/dotted lines + // Since we don't have a way to represent this internally yet, + // use leave line_width at the default. + if(rec->lineweight) + rte_head->line_width = rec->lineweight; + rte_head->rte_name = xstrdup(rec->name); fs_chain_add( &rte_head->fs, (format_specific_data *)rec ); route_add_head(rte_head); for (j = 0; j < (unsigned) rec->pointcount; j++ ) { @@ -847,7 +856,7 @@ Write_One_AN1_Line( const route_head *rte ) fs = fs_chain_find( rte->fs, FS_AN1L ); if ( fs ) { - rec = (an1_line_record *)(void *)fs; + rec = (an1_line_record *)(void *)fs; local = 0; switch (output_type_num) { case 1: @@ -918,7 +927,7 @@ Write_One_AN1_Line( const route_head *rte ) rec->unk4 = 2; rec->lineweight = 6; rec->linecolor = opt_color_num; /* red */ - rec->unk5 = 3; + rec->opacity = 3; rec->unk8 = 2; break; } diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index 40932e7b5..c4ded48de 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -289,6 +289,12 @@ typedef struct format_specific_data { fs_convert convert; } format_specific_data; +typedef struct { + int bbggrr; // 32 bit color: Blue/Green/Red. < 0 == unknown. + unsigned char opacity; // 0 == transparent. 255 == opaque. +} gb_color; + + format_specific_data *fs_chain_copy( format_specific_data *source ); void fs_chain_destroy( format_specific_data *chain ); format_specific_data *fs_chain_find( format_specific_data *chain, long type ); @@ -452,6 +458,8 @@ typedef struct { int rte_waypt_ct; /* # waypoints in waypoint list */ format_specific_data *fs; unsigned short cet_converted; /* strings are converted to UTF8; interesting only for input */ + gb_color line_color; /* Optional line color for rendering */ + int line_width; /* in pixels (sigh). < 0 is unknown. */ } route_head; /* diff --git a/gpsbabel/kml.c b/gpsbabel/kml.c index c72c34a42..e81790b59 100644 --- a/gpsbabel/kml.c +++ b/gpsbabel/kml.c @@ -717,6 +717,17 @@ static void kml_output_tailer(const route_head *header) kml_write_xml(1, "\n"); kml_write_xml(0, "Path\n"); kml_write_xml(0, "#lineStyle\n"); + if (header->line_color.bbggrr >= 0 || header->line_width >= 0) { + kml_write_xml(1, "\n"); + } kml_write_xml(1, "\n"); if (floating) { kml_write_xml(0, "absolute\n"); -- 2.30.2